home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / CHARCNT.C < prev    next >
C/C++ Source or Header  |  1993-08-23  |  2KB  |  92 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    charcnt.c
  5. //   Title:    Data Compression Library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This is a utility to count the frequency of characters directed to it
  25. //    through standard input.
  26. //
  27. //    The code in this module should be written entirely in C. 
  28. //    Do not use any C++ constructs.
  29. //
  30. //    This module is portable to:
  31. //        DOS 3.X+
  32. //        MS Windows 3.X+
  33. //        OS/2 2.X+
  34. //        OS/2 2.0 PM
  35. //        SCO UNIX.
  36. //
  37. //    The following compilers are supported:
  38. //        MSC 6.0A
  39. //        MSC/C++ 7.0
  40. //        Borland C++ 3.1 for DOS
  41. //        Borland C++ 1.0 for OS/2 2.X
  42. //        SCO UNIX cc
  43. //
  44. //----------------------------------------------------------------------------
  45. #include <stdio.h>
  46. #include <ctype.h>
  47.  
  48.  
  49. //----------------------------------------------------------------------------
  50. //   Description:    
  51. //    Parameters:
  52. //       Returns:    
  53. //----------------------------------------------------------------------------
  54. int main(void)
  55. {
  56. static long count[128];
  57.     long total = 0;
  58.     long max_count;
  59.     int i, max_char;
  60.     int ch;
  61.  
  62.     while ((ch = getchar()) != EOF)
  63.         {
  64.         ch &= 0x7F;
  65.         ch = toupper(ch);
  66.         total++;
  67.         count[ch]++;
  68.         }
  69.     printf("%ld characters.\n", total);
  70.     do
  71.         {
  72.         max_count = 0;
  73.         for (i = 0; i < 128; ++i)
  74.             if (count[i] > max_count)
  75.                 {
  76.                 max_char = i;
  77.                 max_count = count[i];
  78.                 }
  79.         if (max_count)
  80.             {
  81.             ch = (int)(isprint(max_char) ? max_char: ' ');
  82.             printf("   '%c' (%3d) %ld\n", ch, ch, count[max_char]);
  83.             count[max_char] = 0;
  84.             }
  85.         }
  86.     while (max_count);
  87.     return 0;
  88. }
  89. //----------------------------------------------------------------------------
  90. //------------------------------- End of File --------------------------------
  91. //----------------------------------------------------------------------------
  92.